/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package doan;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Windows 7
 */
public class Form2_1 extends javax.swing.JFrame {

    /**
     * Creates new form Form2_1
     */
    public Form2_1() {
        initComponents();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        tf21_Username = new javax.swing.JTextField();
        tf21_Pass = new javax.swing.JPasswordField();
        bt21_Create = new javax.swing.JButton();
        bt21_Cancel = new javax.swing.JButton();
        bt21_Logout = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 600));
        getContentPane().setLayout(null);

        jPanel1.setMinimumSize(new java.awt.Dimension(800, 600));
        jPanel1.setPreferredSize(new java.awt.Dimension(800, 600));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        tf21_Username.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        tf21_Username.setText("User Name");
        tf21_Username.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf21_UsernameActionPerformed(evt);
            }
        });
        jPanel1.add(tf21_Username, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 300, 210, 50));

        tf21_Pass.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        tf21_Pass.setText("jPasswordField1");
        tf21_Pass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf21_PassActionPerformed(evt);
            }
        });
        jPanel1.add(tf21_Pass, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 370, 210, 50));

        bt21_Create.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        bt21_Create.setText("Create");
        bt21_Create.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt21_CreateActionPerformed(evt);
            }
        });
        jPanel1.add(bt21_Create, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 450, 120, -1));

        bt21_Cancel.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        bt21_Cancel.setText("Cancel");
        bt21_Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt21_CancelActionPerformed(evt);
            }
        });
        jPanel1.add(bt21_Cancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 450, -1, -1));

        bt21_Logout.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
        bt21_Logout.setText("Log out");
        bt21_Logout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt21_LogoutActionPerformed(evt);
            }
        });
        jPanel1.add(bt21_Logout, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 500, -1, -1));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/doan/mslide2_1.jpg"))); // NOI18N
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 800, 600));

        getContentPane().add(jPanel1);
        jPanel1.setBounds(-20, 0, 800, 600);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tf21_UsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf21_UsernameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf21_UsernameActionPerformed

    private void bt21_CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt21_CancelActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        Form2 t=new Form2();
        t.setVisible(true);
    }//GEN-LAST:event_bt21_CancelActionPerformed

    private void bt21_LogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt21_LogoutActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        Form1 t2 = null;
        try {
            t2 = new Form1();
        } catch (Exception ex) {
            Logger.getLogger(Form2_1.class.getName()).log(Level.SEVERE, null, ex);
        }
        t2.setVisible(true);
    }//GEN-LAST:event_bt21_LogoutActionPerformed

    private void tf21_PassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf21_PassActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf21_PassActionPerformed

    private void bt21_CreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt21_CreateActionPerformed
        // TODO add your handling code here:
        String st1=tf21_Username.getText(),st2=tf21_Pass.getText();
        
        try{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String url ="Jdbc:odbc:doan";
		Connection conn = DriverManager.getConnection(url);
		Statement stt=conn.createStatement();
                PreparedStatement stmt = conn.prepareStatement("INSERT INTO User(name, password) VALUES (?, ?)");

                stmt.setString(1, st1);
                stmt.setString(2, st2);

                stmt.executeUpdate();
                
//                String sql="INSERT INTO User(name, password) VALUES(tf21_Username.getTxet(),tf21_Pass.getText())";
//                
//		 stt.executeUpdate(sql);
		
                } catch (Exception ex) {
                    System.out.println("Loi thao tac CSDL");
            Logger.getLogger(Form2_1.class.getName()).log(Level.SEVERE, null, ex);        }
            //catch (SQLException ex) {
//            Logger.getLogger(Form2_1.class.getName()).log(Level.SEVERE, null, ex);
//        }
 
    }//GEN-LAST:event_bt21_CreateActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Form2_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Form2_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Form2_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Form2_1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Form2_1().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt21_Cancel;
    private javax.swing.JButton bt21_Create;
    private javax.swing.JButton bt21_Logout;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField tf21_Pass;
    private javax.swing.JTextField tf21_Username;
    // End of variables declaration//GEN-END:variables
}
